﻿using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestDxfDocument
{
    class StraightFluteTapClass
    {

        public static void StraightFluteTap1(Dictionary<string, Object> data)//直槽丝锥
        {
            DxfDocument dxf = new DxfDocument();

            #region 图层

            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层

            #endregion

            #region 参数

            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);
            //double scale = Convert.ToDouble(data["scale"]);
            double scale = 5;


            /*double tcl = 4 * scale;
            double td = 4 * scale;
            double thl = 16 * scale;
            double oal = 40 * scale;
            double dmm = 3.8 * scale;
            double dn;
            double drvl;
            double lu;
            try
            {
                dn = Convert.ToDouble(data["dn"]) * scale;
            }
            catch
            {
                dn = dmm - dmm / 10.0;
            }
            try
            {
                drvl = Convert.ToDouble(data["drvl"]) * scale;
            }
            catch
            {
                drvl = 3.25 * (oal / 40.0);
            }
            try
            {
                lu = Convert.ToDouble(data["lu"]) * scale;
            }
            catch
            {
                lu = oal * (26 / 40.0);
            }
            double drvsc = 4 * scale;
            double p = 1*scale ;//螺距
            double h = 0.866025*scale ;//根据螺纹牙型标准中的p得知h牙高的值
            double k = 8.30;//螺纹头部断开角度
            double k_ = k * pi / 180;
            double an = 0;
            double an_ = an * pi / 180;
            double tcl = 4;
            double ap = 0;
            double γp = 5;
            double ap_ = ap * pi / 180;


            double fha = 85;//定值，螺纹线偏角，看情况改
            double fha_ = fha * pi / 180;
            */
            double tcl = Convert.ToDouble(data["tcl"]);
            double thl = Convert.ToDouble(data["thl"]) * scale;
            double oal = Convert.ToDouble(data["oal"]) * scale;

            double td = Convert.ToDouble(data["td"]) * scale;
            double dmm = Convert.ToDouble(data["dconms"]) * scale;

            double fs = Convert.ToDouble(data["fs"]);//刃槽数
            //double fs = 3;//刃槽数


            double dn;
            double drvl;
            double lu;
            try
            {
                dn = Convert.ToDouble(data["dn"]) * scale;
            }
            catch
            {
                dn = dmm - dmm / 10.0;
            }
            try
            {
                drvl = Convert.ToDouble(data["drvl"]) * scale;
            }
            catch
            {
                drvl = 3.25 * (oal / 40.0);
            }
            try
            {
                lu = Convert.ToDouble(data["lu"]) * scale;
            }
            catch
            {
                lu = oal * (26 / 40.0);
            }
            double drvsc = Convert.ToDouble(data["drvsc"]) * scale;
            double p = Convert.ToDouble(data["tp"]) * scale;//螺距
            double h = Convert.ToDouble(data["h"]) * scale;//根据螺纹牙型标准中的p得知h牙高的值

            double k_ = Math.Atan(h / (tcl * scale));
            double an = Convert.ToDouble(data["an"]);
            double ap = Convert.ToDouble(data["ap"]);
            double γp = Convert.ToDouble(data["rp"]);

            double fha = 85;//定值，螺纹线偏角，看情况改
            double ap_ = 0;
            double fha_ = fha * pi / 180;

            #endregion

            #region 点线

            //中图
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, 0, oal + 5);
            Vector2 p0_2 = fun.Polar(p0, pi, 5);
            Vector2 p1_1 = fun.Polar(p0, pi / 2, td / 2.0 - h * 2);
            Vector2 p1_2 = fun.Polar(p1_1, k_, oal);
            Vector2 p1_3 = fun.Polar(p0, pi / -2, td / 2.0 - h);
            Vector2 p1_4 = fun.Polar(p1_3, -k_, oal);

            //虚拟矩阵，不显示
            Vector2 p1 = fun.Polar(p0, pi / 2, td / 2.0 - h);
            Vector2 p2 = fun.Polar(p1, 0, thl);
            Vector2 p3 = fun.Polar(p2, pi / -2, td / 2.0);
            Vector2 p4 = fun.Polar(p0, pi / -2, td / 2.0 - h);

            //螺尖丝锥头部缺失

            Vector2 p60 = fun.Polar(p0, pi / 2, td / 10.0);
            Vector2 p61 = new Vector2(p * tcl, (5.376 / 20.0) * td);
            Vector2 p63 = p0;
            Vector2 p64 = new Vector2(p * tcl, (0.7 / 20.0) * td);
            Vector2 p65 = new Vector2(p * tcl, (5.376 / 20.0) * td + 0.1 * (td / 20.0));
            Vector2 p66 = fun.Polar(p65, pi, oal);
            Vector2 p67 = fun.Polar(p61, 0, 1.835 * (td / 20.0));
            Vector2 p72 = fun.Polar(p67, 90.001 * pi / 180, oal);

            //螺纹
            Vector2 p7 = p0;
            Vector2 p5 = p0;
            Vector2 p6 = p0;
            Vector2 p8 = p0;
            Vector2 p9 = p0;
            Vector2 p10 = p0;
            Vector2 p11 = p0;
            Vector2 p12 = p0;
            Vector2 p13 = p0;
            Vector2 p14 = p0;
            Vector2 p15 = p0;
            Vector2 p16 = p0;
            Vector2 p17 = p0;
            Vector2 p18 = p1_1;
            Vector2 p19 = p0;
            Vector2 p20 = p0;
            Vector2 p21 = p0;
            var polyline1 = Pus.AddPointsToLwPolyLine(p0);
            var polyline1_1 = Pus.AddPointsToLwPolyLine(p0);
            var polyline2 = Pus.AddPointsToLwPolyLine(p0);

            for (int i = 0; i < tcl; i++)
            {
                if (i == 0)
                {
                    p5 = fun.Polar(p7, pi / 2, td / 2 - h * 2);
                    p10 = new Vector2(p5.X + (td / 2 - h) / Math.Tan(fha_), -p5.Y);
                }
                else
                {
                    p5 = p7;
                    p10 = p13;
                }
                p6 = new Vector2(p5.X + p / 2.0, p5.Y + h);
                p7 = new Vector2(p6.X + (p6.X - p5.X), p5.Y);
                p8 = fun.Inters(p5, p6, p1_1, p1_2);
                Vector2 p8_1 = fun.Polar(p8, pi / 2, h);
                p9 = fun.Inters(p6, p7, p1_1, p1_2);
                Vector2 p9_1 = fun.Polar(p9, pi / 2, h);
                p11 = new Vector2(p8.X + (td / 2 - h) / Math.Tan(fha_), -p8.Y);
                p12 = new Vector2(p9.X + (td / 2 - h) / Math.Tan(fha_), -p9.Y);
                p13 = new Vector2(p7.X + (td / 2 - h) / Math.Tan(fha_), -p7.Y);
                p14 = fun.Inters(p5, p10, p0_1, p0_2);
                p15 = fun.Inters(p8, p11, p0_1, p0_2);
                p16 = fun.Inters(p9, p12, p0_1, p0_2);
                p17 = fun.Inters(p7, p13, p0_1, p0_2);
                p19 = fun.Polar(p18, pi / -2, td - 4 * h);
                p20 = fun.Polar(p19, 0, (td / 2 - h) / Math.Tan(fha_));

                Vector2 p68 = fun.Inters(p14, p10, p63, p64);
                Vector2 p69 = fun.Inters(p15, p11, p63, p64);
                Vector2 p70 = fun.Inters(p16, p12, p63, p64);
                Vector2 p71 = fun.Inters(p17, p13, p63, p64);
                if (p68.Y > 0)
                {
                    p68 = fun.Inters(p14, p10, p0_1, p0_2);
                }
                else
                {
                    p68 = fun.Inters(p14, p10, p63, p64);
                }
                if (p69.Y > 0)
                {
                    p69 = fun.Inters(p15, p11, p0_1, p0_2);
                }
                else
                {
                    p69 = fun.Inters(p15, p11, p63, p64);
                }
                if (p70.Y > 0)
                {
                    p70 = fun.Inters(p16, p12, p0_1, p0_2);
                }
                else
                {
                    p70 = fun.Inters(p16, p12, p63, p64);
                }
                if (p71.Y > 0)
                {
                    p71 = fun.Inters(p17, p13, p0_1, p0_2);
                }
                else
                {
                    p71 = fun.Inters(p17, p13, p63, p64);
                }
                polyline1 = Pus.AddPointsToLwPolyLine(p5, p8, p9, p7);
                polyline1_1 = Pus.AddPointsToLwPolyLine(p8, p8_1, p8, p9, p9_1, p9);
                polyline2 = Pus.AddPointsToLwPolyLine(p68, p10, p11, p69, p11, p12, p70, p12, p13, p71, p13);
                var polyline3 = Pus.AddPointsToLwPolyLine(p18, p19, p20);

                p21 = fun.Polar(p0, pi / 2, h);
                Vector2 p21_3 = fun.Polar(p0, 0, (td / 2 - h) / Math.Tan(fha_));
                var polyline4 = Pus.OffsetLwPolyline(polyline1, p21);
                var polyline4_1 = Pus.MirrorPolyline(polyline4, p0_1, p0_2);
                var polyline4_2 = Pus.OffsetLwPolyline(polyline4_1, p21_3);
                fun.PolyFill(dxf, polyline1, 0.5, contour);
                fun.PolyFill(dxf, polyline1_1, 0.5, contour);

                fun.PolyFill(dxf, polyline2, 0.5, contour);

                fun.PolyFill(dxf, polyline3, 0.5, contour);
                fun.PolyFill(dxf, polyline4, 0.5, contour);
                fun.PolyFill(dxf, polyline4_2, 0.5, contour);

            }

            double a1 = (thl - p * tcl) / (p);
            int a2 = (int)a1;

            for (int j = 0; j < a2; j++)
            {
                p5 = p7;
                p6 = new Vector2(p5.X + p / 2.0, p5.Y + h);
                Vector2 p6_1 = fun.Polar(p6, pi / 2, h);
                p7 = new Vector2(p6.X + (p6.X - p5.X), p5.Y);
                p8 = new Vector2(p5.X + (td / 2 - h) / Math.Tan(fha_), -p5.Y);
                p9 = new Vector2(p6.X + (td / 2 - h) / Math.Tan(fha_), -p6.Y);
                p10 = new Vector2(p7.X + (td / 2 - h) / Math.Tan(fha_), -p7.Y);
                p14 = fun.Inters(p8, p5, p0_1, p0_2);
                p15 = fun.Inters(p9, p6, p0_1, p0_2);
                p16 = fun.Inters(p10, p7, p0_1, p0_2);
                polyline2 = Pus.AddPointsToLwPolyLine(p14, p8, p9, p15, p9, p10, p16, p10);
                polyline1 = Pus.AddPointsToLwPolyLine(p5, p6, p7);
                polyline1_1 = Pus.AddPointsToLwPolyLine(p6, p6_1);
                p21 = new Vector2(0, h);
                Vector2 p21_1 = fun.Polar(p0, 0, (td / 2 - h) / Math.Tan(fha_));
                var polyline4 = Pus.OffsetLwPolyline(polyline1, p21);
                var polyline4_1 = Pus.MirrorPolyline(polyline4, p0_1, p0_2);
                var polyline4_2 = Pus.OffsetLwPolyline(polyline4_1, p21_1);
                fun.PolyFill(dxf, polyline1, 0.5, contour);
                fun.PolyFill(dxf, polyline1_1, 0.5, contour);
                fun.PolyFill(dxf, polyline2, 0.5, contour);
                fun.PolyFill(dxf, polyline4, 0.5, contour);
                fun.PolyFill(dxf, polyline4_2, 0.5, contour);
            }

            Vector2 p22 = fun.Polar(p0, pi / -2, td / 2.0 - h);
            Vector2 p23 = fun.Polar(p22, 0, (td / 2 - h) / Math.Tan(fha_));
            var polyline5 = Pus.AddPointsToLwPolyLine(p0, p22, p23);
            fun.PolyFill(dxf, polyline5, 0.5, contour);

            //柄部
            Vector2 p25 = fun.Polar(p7, pi / 2, h);
            Vector2 p25_1 = p25;
            Vector2 p26 = fun.Polar(p25, pi / -2, td - h * 2);
            Vector2 p27 = fun.Polar(p26, 0, (td / 2 - h) / Math.Tan(fha_));
            Vector2 p27_1 = p27;
            Vector2 p28_1 = fun.Polar(p7, pi / -2, td - 4 * h);
            Vector2 p28 = fun.Polar(p28_1, 0, (td / 2 - h) / Math.Tan(fha_));
            Vector2 p29 = new Vector2(lu, p25.Y);
            Vector2 p30 = new Vector2(p29.X, dmm / 2.0);
            p29 = (dmm > td - h * 2) ? p30 : p29;

            Vector2 p31 = fun.mirrorpoint(p29, p0_1, p0_2);
            Vector2 p32 = fun.mirrorpoint(p30, p0_1, p0_2);
            Vector2 p33 = fun.Polar(p30, 0, oal - lu);
            Vector2 p34 = fun.mirrorpoint(p33, p0_1, p0_2);
            Vector2 p35_1 = fun.Polar(p33, pi / -2, dmm / 2.0 - dmm / 2.0 / 10.0);
            Vector2 p35 = fun.Polar(p35_1, pi, 0.42 * (oal / 40.0));
            Vector2 p36 = fun.Polar(p33, pi, drvl);
            Vector2 p37 = new Vector2(p36.X, p35.Y);
            Vector2 p38 = fun.mirrorpoint(p35, p0_1, p0_2);
            Vector2 p39 = fun.mirrorpoint(p36, p0_1, p0_2);
            Vector2 p40 = fun.mirrorpoint(p37, p0_1, p0_2);
            Vector2 p41 = new Vector2(p35.X, p36.Y);
            Vector2 p42 = new Vector2(p38.X, p39.Y);

            var polyline6 = Pus.AddPointsToLwPolyLine(p28, p27, p27_1, p31, p32, p42, p40, p38, p35, p36, p41, p30, p32, p29, p25_1, p7);
            var polyline7 = Pus.AddPointsToLwPolyLine(p42, p40, p38, p39, p42, p39, p40, p38, p35, p36, p41, p37, p35, p37, p36, p41);
            Line line1 = new Line(p33, p34);
            Arc arc1 = fun.DrawArc3(p35, new Vector2(p33.X, (p35 + p41).Y / 2), p41);
            Arc arc2 = fun.DrawArc3(p42, new Vector2(p33.X, (p42 + p38).Y / 2), p38);

            fun.PolyFill(dxf, polyline6, 0.5, contour);
            fun.PolyFill(dxf, polyline7, 0.5, contour);
            fun.drawBArc(dxf, arc1, 0.5, contour);
            fun.drawBArc(dxf, arc2, 0.5, contour);





            //颈部
            Vector2 p43 = fun.Polar(p7, pi / -2, oal);
            Vector2 p44 = new Vector2((p7.X + p10.X) / 2, 0);

            Vector2 p45 = new Vector2(p44.X + (lu - thl) / 4, p7.Y / 6);
            Vector2 p46 = new Vector2(p45.X, p7.Y - p7.Y / 6);
            Vector2 p45_1 = new Vector2(p45.X + (lu - thl) / 4, p7.Y / 2);

            Vector2 p47 = fun.Polar(p28, 0, p45.X - p44.X);
            Vector2 p48 = new Vector2(p45_1.X, p27.Y);
            p48 = (dmm > td - h * 2) ? (p27 + p31) / 2 : p48;

            var polyline13 = Pus.AddPointsToLwPolyLine(p44, p45, p45_1, p46, p7);
            polyline13 = Pus.Fillet4LwPline(polyline13, 2, p7.Y / 16);
            polyline13.Vertexes[0].Bulge = Math.Tan((6 * pi / 180) / 4);
            polyline13.Vertexes[1].Bulge = Math.Tan((6 * pi / 180) / 4);
            polyline13.Vertexes[3].Bulge = Math.Tan((6 * pi / 180) / 4);
            polyline13.Vertexes[4].Bulge = Math.Tan((6 * pi / 180) / 4);


            var polyline14 = Pus.AddPointsToLwPolyLine((p27 + p48) / 2, p28, p48);

            fun.PolyFill(dxf, polyline13, 0.5, contour);
            fun.PolyFill(dxf, polyline14, 0.5, contour);


            //右图
            try
            {
                drvsc = Convert.ToDouble(data["drvsc"]) * scale;

            }
            catch
            {
                drvsc = td;
            }
            Vector2 p50 = p0;
            Vector2 p51 = p0;
            Vector2 p49_1 = fun.Polar(p0, pi, dmm * 2 + 40);
            Vector2 p49 = fun.Polar(p0, 0, oal + oal / 3.0);
            p50 = fun.Polar(p49, pi / 2, drvsc / 2.0);
            Vector2 p50_1 = fun.Polar(p50, pi + pi / 4, drvsc / 10.0);
            Vector2 p50_2 = fun.Polar(p50, pi / -4, drvsc / 10.0);
            p51 = fun.Polar(p49, 0, drvsc / 2.0);
            Vector2 p51_1 = fun.Polar(p51, pi - pi / 4, drvsc / 10.0);
            Vector2 p51_2 = fun.Polar(p51, pi + pi / 4, drvsc / 10.0);
            Vector2 p52 = fun.Polar(p49, pi / -2, drvsc / 2.0);
            Vector2 p52_1 = fun.Polar(p52, pi / 4, drvsc / 10.0);
            Vector2 p52_2 = fun.Polar(p52, pi - pi / 4, drvsc / 10.0);
            Vector2 p53 = fun.Polar(p49, pi, drvsc / 2.0);
            Vector2 p53_1 = fun.Polar(p53, pi / -4, drvsc / 10.0);
            Vector2 p53_2 = fun.Polar(p53, pi / 4, drvsc / 10.0);
            var polyline9 = Pus.AddPointsToLwPolyLine(p50_1, p50_2, p51_1, p51_2, p52_1, p52_2, p53_1, p53_2, p50_1);
            polyline9.Vertexes[0].Bulge = -Math.Tan((90 * pi / 180) / 4);
            polyline9.Vertexes[2].Bulge = -Math.Tan((90 * pi / 180) / 4);
            polyline9.Vertexes[4].Bulge = -Math.Tan((90 * pi / 180) / 4);
            polyline9.Vertexes[6].Bulge = -Math.Tan((90 * pi / 180) / 4);

            fun.PolyFill(dxf, polyline9, 0.5, contour);

            fun.AddHatch(dxf, hatching, polyline9, new Line[32], new Arc[32], 45, 10);


            //左图

            Circle circle1 = new Circle(p49_1, dmm / 2.0);
            Circle circle2 = new Circle(p49_1, td / 2.0);//外轮廓参照

            Arc arc2_1 = fun.DrawArc4(fun.Polar(p49_1, 0, td / 2.0), circle2.Radius, fun.Polar(p49_1, 179.99 * pi / 180, td / 2.0), 0);
            Vector2 p54 = fun.Polar(p49_1, pi / 2, td / 2.0);
            Vector2 p54_1 = fun.Polar(fun.PointRotate(p54, p49_1, ap_), pi / -4, dmm * (1 / 19.0));
            Vector2 p55 = fun.Polar(p49_1, pi / 6, td / 2.0);
            Vector2 p56 = fun.Polar(p49_1, pi / 2, td / 2.0 - h);
            Vector2 p57 = fun.Polar(p49_1, pi / 6, td / 2.0 - h);


            //Circle circle3 = new Circle(p49_1, dmm / 2.0);
            //circle3.Layer = center;
            //dxf.AddEntity(circle3);

            //Circle circle4 = new Circle(p49_1, dmm / 4.0);
            //circle4.Layer = center;
            //dxf.AddEntity(circle4);

            Line linec1 = new Line(fun.Polar2(p49_1, td / 2 + 2, 180), fun.Polar2(p49_1, td / 2 + 2, 0));
            Line linec2 = fun.RotateLine(linec1, p49_1, 90);

            //Circle circle5 = new Circle(p49_1, dmm / 2.0);
            //Circle circle6 = new Circle(p49_1, dmm / 4.0);


            //fun.drawcircle(dxf, p49_1, td / 2 - h, 0.5, contour);

            for (int j = 0; j < fs; j++)
            {
                if (fs == 2)
                {
                    p55 = fun.Polar(p49_1, 0, td / 2.0 + 2 * h);
                    p57 = fun.Polar(p49_1, 0, td / 2.0 - td / 15.0 + 2 * h);
                }

                Arc arc5 = fun.DrawArc(p55, p49_1, p54);
                Vector2 arc5_1 = fun.PointRotate(Pus.ToV2(arc5.Center), fun.Polar(Pus.ToV2(arc5.Center), arc5.StartAngle * pi / 180, arc5.Radius), 360 / fs * j * pi / 180);
                Vector2 arc5_2 = fun.PointRotate(Pus.ToV2(arc5.Center), fun.Polar(Pus.ToV2(arc5.Center), arc5.EndAngle * pi / 180, arc5.Radius), 360 / fs * j * pi / 180);
                arc5 = fun.DrawArc(arc5_1, Pus.ToV2(arc5.Center), arc5_2);

                Arc arc6 = fun.Rotatingcircle(arc5, p54, ap_);
                Vector2 arc6_1 = fun.PointRotate(Pus.ToV2(arc6.Center), fun.Polar(Pus.ToV2(arc6.Center), arc6.StartAngle * pi / 180, arc6.Radius), 360 / fs * j * pi / 180);
                Vector2 arc6_2 = fun.PointRotate(Pus.ToV2(arc6.Center), fun.Polar(Pus.ToV2(arc6.Center), arc6.EndAngle * pi / 180, arc6.Radius), -360 / fs * j * pi / 180);
                arc6 = fun.DrawArc(arc6_1, Pus.ToV2(arc6.Center), arc6_2);

                Arc arc7 = fun.DrawArc(p57, p49_1, p56);
                Vector2 arc7_1 = fun.PointRotate(Pus.ToV2(arc7.Center), fun.Polar(Pus.ToV2(arc7.Center), arc7.StartAngle * pi / 180, arc7.Radius), 360 / fs * j * pi / 180);
                Vector2 arc7_2 = fun.PointRotate(Pus.ToV2(arc7.Center), fun.Polar(Pus.ToV2(arc7.Center), arc7.EndAngle * pi / 180, arc7.Radius), 360 / fs * j * pi / 180);
                arc7 = fun.DrawArc(arc7_1, Pus.ToV2(arc7.Center), arc7_2);

                Arc arc8 = fun.Rotatingcircle(arc7, p56, ap_);
                Vector2 arc8_1 = fun.PointRotate(Pus.ToV2(arc8.Center), fun.Polar(Pus.ToV2(arc8.Center), arc8.StartAngle * pi / 180, arc8.Radius), 360 / fs * j * pi / 180);
                Vector2 arc8_2 = fun.PointRotate(Pus.ToV2(arc8.Center), fun.Polar(Pus.ToV2(arc8.Center), arc8.EndAngle * pi / 180, arc8.Radius), -360 / fs * j * pi / 180);
                arc8 = fun.DrawArc(arc8_1, Pus.ToV2(arc8.Center), arc8_2);


                Vector2 p73 = fun.Polar(arc5_2, -ap_ - 31 * pi / 180 - 360 / fs * j * pi / 180, 5.52 / 20.0 * td);
                Vector2 p74 = fun.PointRotate(fun.PointRotate(p54, p49_1, ap_), arc5_2, (360 - 180 / fs) * pi / 180);
                Vector2 p75 = fun.Polar(p74, -ap_ - 31 * pi / 180 - 360 / fs * j * pi / 180, 8.16 / 20.0 * td);
                Vector2 p76_1 = fun.Polar(p49_1, pi / 2 - 360 / fs * j * pi / 180, dmm / 4.0);

                Vector2 p76 = fun.Polar(p76_1, pi - 360 / fs * j * pi / 180, oal);
                Vector2 p77 = fun.Polar(p76, 0 - 360 / fs * j * pi / 180, oal);

                Line line5 = new Line(arc5_2, p73);
                Line line6 = new Line(p74, p75);
                Arc arc10 = fun.DrawArc5(p75, new Line(p76, p77), p73);


                if (ap_ == 0)
                {
                    Vector2 p58 = fun.Polar(Pus.ToV2(arc5.Center), (arc5.StartAngle) * pi / 180 - pi / fs, arc5.Radius);
                    Vector2 p59 = fun.Polar(Pus.ToV2(arc7.Center), (arc7.StartAngle) * pi / 180 - pi / fs, arc7.Radius);
                    Arc arc9 = fun.DrawArc3(fun.Polar(Pus.ToV2(arc5.Center), (arc5.StartAngle) * pi / 180, arc5.Radius), p59, p58);
                    fun.drawBArc(dxf, arc5, 0.5, contour);
                    fun.drawBArc(dxf, arc7, 0.5, contour);
                    fun.drawBArc(dxf, arc9, 0.5, contour);
                }
                else
                {
                    Vector2 p58 = fun.Polar(Pus.ToV2(arc6.Center), (arc6.StartAngle) * pi / 180 - pi / fs, arc6.Radius);
                    Vector2 p59 = fun.Polar(Pus.ToV2(arc8.Center), (arc8.StartAngle) * pi / 180 - pi / fs, arc8.Radius);
                    Arc arc9 = fun.DrawArc3(fun.Polar(Pus.ToV2(arc6.Center), (arc6.StartAngle) * pi / 180, arc6.Radius), p59, p58);
                    fun.drawBArc(dxf, arc6, 0.5, contour);
                    fun.drawBArc(dxf, arc8, 0.5, contour);
                    fun.drawBArc(dxf, arc9, 0.5, contour);
                }

            }


            //中心线
            Line line1_1 = new Line(p0_1, p0_2);
            line1_1.Layer = center;
            dxf.AddEntity(line1_1);

            Vector2 vector1 = fun.Polar(p0, pi / 2, (td - h * 2) / 4.0);
            Vector2 vector2 = fun.Polar(p0, pi, (td - h * 2) / 4.0);
            Vector2 vector3 = fun.Polar(p0, -pi / 2, (td - h * 2) / 4.0);

            #endregion

            #region 线
            Vector2 v0 = fun.Polar(p34, pi / 2, fun.CalDistance(p33, p34) / 2.0);

            LwPolyline lw1 = Pus.AddPointsToLwPolyLine(vector1, vector2, vector3);
            Line line3 = new Line(fun.Polar2(v0, dmm / 4, 90), fun.Polar2(v0, dmm / 4, -90));
            Line line4 = new Line(p0, p44);
            #endregion

            #region 标注
            double tcpd = td - h * 2;
            double height = 3.5;
            double arrowsize = height;
            double offset = 10;
            double exline = height / 2;
            double jj = 1;

            Vector2 v1 = fun.Polar(p0, pi / 2, td / 2 - h);
            Vector2 v2 = fun.Polar(p0, pi / -2, td / 2 - h);
            Vector2 v3 = fun.Polar(p0, pi / 2, td / 2.0);
            Vector2 v4 = fun.Polar(v3, 0, tcl * p);
            Vector2 v5 = fun.mirrorpoint(v4, p0_1, p0_2);
            Vector2 v6 = fun.Polar(p34, pi / 2, fun.CalDistance(p33, p34) / 2.0);
            Vector2 v8 = fun.PointRotate(p54, p55, ap_);
            Vector2 v9 = fun.Polar(p34, pi / 2, fun.CalDistance(p34, p33) / 2.0);
            Vector2 v10 = fun.Polar(v9, 0, 5 * (oal / 40.0) / 4.0);
            Vector2 v11 = fun.Polar(v10, 0, 5 * (oal / 40.0) / 4.0);
            Vector2 v12 = fun.Polar(p53, pi / -2, dmm);
            Vector2 v13 = fun.Polar(v4, 0, p);

            Vector2 v14 = fun.Polar((p39 + p42) / 2, -pi / 2, offset);
            Vector2 v15 = fun.mirrorpoint(v14, p0_1, p0_2);
            Line line2 = new Line(v14, v15);



            fun.dimrot1(dxf, p0, v4, 0, offset + v4.Y / 2, jj, height, arrowsize, exline, "TCL=" + tcl, "", "");
            fun.dimrot1(dxf, v4, v5, 90, offset + v4.X, jj, height, arrowsize, exline, "TD=" + td / scale, "", "");
            fun.dimrot1(dxf, p0, p44, 180, offset + v4.Y, jj, height, arrowsize, exline, "THL=" + thl / scale, "", "");
            fun.dimrot1(dxf, p33, p34, -90, offset, jj, height, arrowsize, exline, "DCONMS=" + dmm / scale, "", "");
            fun.dimrot1(dxf, p6, fun.Polar2(p6, p, 180), 0, offset + h, jj, height, arrowsize, exline, "  TP=" + p / scale, "", "");



            fun.jt(dxf, v14, 180, offset / 3, height, "A");
            fun.jt(dxf, v15, 180, offset / 3, height, "A");
            Text txt1 = new Text("A-A", fun.Polar2(p50, offset, 120), height, 0);
            dxf.AddEntity(txt1);

            try
            {
                dn = Convert.ToDouble(data["dn"]) * scale;
                fun.dimrot1(dxf, p31, p29, -90, offset, 2, height, arrowsize, exline, "  DN=" + dn / scale, "", "");
            }
            catch
            { }

            try
            {
                drvsc = Convert.ToDouble(data["drvsc"]) * scale;
                fun.dimrot(dxf, p52, p51, -135, offset, height, arrowsize, exline, "  DRVSC=" + drvsc / scale, "", "");
            }
            catch
            { }

            try
            {
                lu = Convert.ToDouble(data["lu"]) * scale;
                Vector2 v7 = fun.Polar(p0, 0, lu);
                fun.dimrot1(dxf, p0, v6, 180, offset * 3 + v4.Y, 2, height, arrowsize, exline, "OAL=" + oal / scale, "", "");
                fun.dimrot1(dxf, p0, v7, 180, offset * 2 + v4.Y, 2, height, arrowsize, exline, "  LU=" + lu / scale, "", "");
            }
            catch
            {
                fun.dimrot1(dxf, p0, v6, 0, offset * 3 + v4.Y, 2, height, arrowsize, exline, "OAL=" + oal / scale, "", "");
            }

            try
            {
                drvl = Convert.ToDouble(data["drvl"]) * scale;
                fun.dimrot1(dxf, p39, v6, 180, offset * 2, 2, height, arrowsize, exline, "DRVL=" + drvl / scale, "", "");
            }
            catch { }



            #endregion


            #region 图框

            fun.DrawFrame(dxf, data, scale, Vector2.Zero);

            #endregion

            #region 编辑

            fun.AddEntities(dxf, center, line2);



            fun.PolyFill(dxf, lw1, 0.5, contour);
            fun.drawBline(dxf, line3, 0.5, contour);
            fun.drawBline(dxf, line4, 0.5, contour);

            fun.AddEntities(dxf, center, linec1, linec2);
            //fun.AddEntities(dxf, refin, circle5, circle6);


            //fun.seevector2(dxf, "p", 1, 1, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
            //fun.seevector2(dxf, "p", 1, 11, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20);
            //fun.seevector2(dxf, "p", 1, 21, p21, p22, p23, p1, p25, p26, p27, p28, p29, p30);
            //fun.seevector2(dxf, "p", 1, 31, p31, p32, p33, p34, p35, p36, p37, p38, p39, p40);
            //fun.seevector2(dxf, "p", 1, 41, p41, p42, p43, p44, p45, p46, p47, p48, p49, p50);
            //fun.seevector2(dxf, "p", 1, 51, p51, p52, p53, p54, p55, p56, p57, p60);
            //fun.seevector2(dxf, "p", 1, 61, p61, p63, p64, p65, p66, p67);


            #endregion


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }


    }
}